package com.karolak.stock.indicator;

import com.karolak.math.formula.Fft;
import com.karolak.stock.data.DataManager;

public class FftInd extends Indicator {

	private int harmonicCount;
	private Fft fft;

	public FftInd(DataManager dataManager, int period, Indicator input, int harmonicCount) {
		super(dataManager, period, input);
		this.harmonicCount = harmonicCount;
		this.fft = new Fft();
		setName(String.format("%s%s", super.getName(), getHarmonicCount()));
	}

	@Override
	public double execute(double x) {
		getFft().reset();
		double[] signal = getDataManager().getSeries(getInput().getName(), getPeriod());
//		Fft fft = new Fft();
		getFft().calculate(signal, getHarmonicCount());
		double value = getFft().getLast(x);
//		update(fft);
		return value;
	}

//	protected void update(Fft fft) {
//		for (int i = 0; i < fft.getHarmonicCount(); i++) {
//			getDataManager().set(String.format("hr.%s", i), fft.getHrLast(i));
//			getDataManager().set(String.format("fr.%s", i), fft.getFrequency(i));
//			getDataManager().set(String.format("pr.%s", i), fft.getPeriod(i));
//			getDataManager().set(String.format("ampl.%s", i), fft.getAmplitude(i));
//		}
//	}

	public int getHarmonicCount() {
		return harmonicCount;
	}

	public Fft getFft() {
		return fft;
	}
}
